package site.xuqing.autohelpertools.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import java.util.Arrays;
import java.util.List;

public class SharedPreferencesUtil {
    private static final String SP_NAME = "AutoHelper";
    private static SharedPreferences sp;
    public static void init(Context applicationContext){
        if(sp==null){
            sp=applicationContext.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        }
    }

    public static void addScreenData(String screenData){
        if (TextUtils.isEmpty(screenData)){
            return;
        }
        String screenDataSave=getScreenData();
        if (screenDataSave==null){
            screenDataSave=screenData;
        }else{
            screenDataSave+=";"+screenData;
        }
        sp.edit().putString("screen_data",screenDataSave).apply();
    }
    public static void clearScreenData(){
        sp.edit().remove("screen_data").apply();
    }
    public static String getScreenData(){
        return sp.getString("screen_data",null);
    }
    public static String[] getScreenDataArray(){
        String screenData=getScreenData();
        if (TextUtils.isEmpty(screenData)){
            return null;
        }else{
            return screenData.split(";");
        }
    }
    public static List<String> getScreenDataList(){
        String[] array=getScreenDataArray();
        if (array==null){
            return null;
        }else{
            return Arrays.asList(array);
        }
    }
}
